<template>
	<view class="demo-switch">
		<!-- <cl-card label="参数设置">
			<text class="label" style="margin-left: 20px;margin-right: 30px;">用户持久化保存时间(天):</text> 
			<cl-switch type="success" v-model="form.a"></cl-switch>
		
		</cl-card> -->
		<cl-form>
			<cl-form-item label="持久化时间:">
				<cl-input v-model="usersavetime"  placeholder="(天)"></cl-input>
			</cl-form-item>
		</cl-form>
		<cl-form>
			<cl-form-item label="文件大小">
				<cl-input v-model="maxuploadbyte"  placeholder="(字节)"></cl-input>
			</cl-form-item>
		</cl-form>
		<cl-form>
			<cl-form-item label="聊天条数:">
				<cl-input v-model="recordcount"  placeholder="聊天记录显示条数"></cl-input>
			</cl-form-item>
		</cl-form>
		
			<text class="label" style="margin-left: 20px;margin-right: 20px;">开启欢迎语:</text> 
			<cl-switch type="success" v-model="showHello"></cl-switch>
		
		<cl-form>
			<cl-form-item label="欢迎语内容" prop="desc">
				<textarea
					class="cl-textarea"
					v-model="helloContent"
				></textarea>
			</cl-form-item>
		</cl-form>
		
		<text class="label" style="margin-left: 20px;margin-right: 20px;">开启离线回复:</text>
			<cl-switch type="success" v-model="showOfflineTip"></cl-switch>
		<cl-form>
			<cl-form-item label="离线回复内容" prop="desc">
				<textarea
					class="cl-textarea"
					v-model="offlineTip"
				></textarea>
			</cl-form-item>
		</cl-form>
		
		
		<view style="text-align: center;" @click="confirm">
			<cl-row>
				<cl-col>
					<cl-button type="primary" style="text-align: center; margin: 0px auto;">
						<text>保存信息</text>
					</cl-button>
				</cl-col>
			</cl-row>
		</view>
		
		
		<!-- <cl-card label="基本用法"> -->
			<cl-loading-mask
				:loading="loading"
				text="数据配置中"
				color="#000"
				fullscreen
			></cl-loading-mask>
			<!-- <cl-button @tap="open()" size="small">
				<text>全屏</text>
			</cl-button> -->
		<!-- </cl-card> -->
		<cl-message ref="message"></cl-message>

		<!-- <cl-form>
			<cl-form-item label="持久化时间(天):">
				<cl-input v-model="usersavetime"  placeholder="请填写名称"></cl-input>
			</cl-form-item>
		</cl-form> -->
	</view>
</template>

<script>
import http from '@/common/requestConfig.js';
export default {
	components: {
		http
	},
	data() {
		return {
				usersavetime:1,
				maxuploadbyte:0,
				recordcount:0,
				showHello:false,
				helloContent:"",
				showOfflineTip:false,
				offlineTip:"",
				loading: false,
		};
	},
	onLoad() {
		var that = this;
		http.post("customer/GetSystemConfig", {}
		).then(res => {
			if(res.code == 1){
				res = res.data;
				that.usersavetime = res.usersavetime;
				that.maxuploadbyte = res.maxuploadbyte;
				that.recordcount = res.recordcount;
				that.showHello = res.showHello == "1"?true:false;
				that.helloContent = res.helloContent;
				that.showOfflineTip = res.showOfflineTip == "1"?true:false;
				that.offlineTip = res.offlineTip;
			}
		}).catch(res=>{
			//console.log('throw error..');
			//that.LoginInfo();
		});
	},
	methods:{
		confirm(){
			var that = this;
			this.loading = true;
			var data = this.$data;
			data.showHello = data.showHello ? "1":"0";
			data.showOfflineTip = data.showOfflineTip ? "1":"0";
			http.post("customer/SetSystemConfig",data
			).then(res => {
				that.loading = false;
				//防止开关问题
				that.showHello = that.showHello == "1"?true:false;
				that.showOfflineTip = that.showOfflineTip == "1"?true:false;
				if(res.code == 1){
					that.openModel('success',res.message);
				}else{
					uni.showModal({
						title:"系统提示",
						content:res.message
					})
				}
			}).catch(res=>{
				//console.log('throw error..');
				//that.LoginInfo();
			});
		},
		openModel(type,message, options) {
			this.$refs["message"].open({
				type,
				message: message,
				...options,
			});
		},
	}
	
};
</script>

<style lang="scss">
.demo-switch {
	background-color: #f7f7f7;
	.label {
		font-size: 26rpx;
	}

	.cl-switch {
		margin-right: 20rpx;
	}
}
</style>